package com.xingqing.controller;

import com.xingqing.domain.vo.EchartsDataVO;
import com.xingqing.domain.vo.JobStatisticsVO;
import com.xingqing.domain.vo.Result;
import com.xingqing.service.EmpStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Autowired
    private EmpStatisticsService empStatisticsService;

    /**
     * 获取职位统计数据（原始数据）
     */
    @GetMapping("/job")
    public Result<List<JobStatisticsVO>> getJobStatistics() {
        log.info("获取职位统计数据");
        List<JobStatisticsVO> statistics = empStatisticsService.getJobStatistics();
        return Result.success(statistics);
    }

    /**
     * 获取职位统计柱状图数据（ECharts格式）
     */
    @GetMapping("/job/bar")
    public Result<EchartsDataVO> getJobStatisticsForBar() {
        log.info("获取职位统计柱状图数据");
        EchartsDataVO data = empStatisticsService.getJobStatisticsForBar();
        return Result.success(data);
    }

    /**
     * 获取职位统计饼图数据（ECharts格式）
     */
    @GetMapping("/job/pie")
    public Result<EchartsDataVO> getJobStatisticsForPie() {
        log.info("获取职位统计饼图数据");
        EchartsDataVO data = empStatisticsService.getJobStatisticsForPie();
        return Result.success(data);
    }

    /**
     * 获取部门统计数据（原始数据）
     */
    @GetMapping("/dept")
    public Result<List<Map<String, Object>>> getDeptStatistics() {
        log.info("获取部门统计数据");
        List<Map<String, Object>> statistics = empStatisticsService.getDeptStatistics();
        return Result.success(statistics);
    }

    /**
     * 获取部门统计图表数据（ECharts格式）
     */
    @GetMapping("/dept/chart")
    public Result<EchartsDataVO> getDeptStatisticsForChart() {
        log.info("获取部门统计图表数据");
        EchartsDataVO data = empStatisticsService.getDeptStatisticsForChart();
        return Result.success(data);
    }

    /**
     * 获取性别统计数据（原始数据）
     */
    @GetMapping("/gender")
    public Result<List<Map<String, Object>>> getGenderStatistics() {
        log.info("获取性别统计数据");
        List<Map<String, Object>> statistics = empStatisticsService.getGenderStatistics();
        return Result.success(statistics);
    }

    /**
     * 获取性别统计图表数据（ECharts格式）
     */
    @GetMapping("/gender/chart")
    public Result<EchartsDataVO> getGenderStatisticsForChart() {
        log.info("获取性别统计图表数据");
        EchartsDataVO data = empStatisticsService.getGenderStatisticsForChart();
        return Result.success(data);
    }

    /**
     * 获取综合统计数据（仪表板用）
     */
    @GetMapping("/dashboard")
    public Result<Map<String, Object>> getDashboardStatistics() {
        log.info("获取仪表板统计数据");
        
        Map<String, Object> dashboard = Map.of(
            "jobStats", empStatisticsService.getJobStatisticsForPie(),
            "deptStats", empStatisticsService.getDeptStatisticsForChart(),
            "genderStats", empStatisticsService.getGenderStatisticsForChart()
        );
        
        return Result.success(dashboard);
    }
}